package Input;

import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import Announcements.Announcement;
import Menus.FireMenu;
import Projectiles.Torpedo;

public class FireMenuInput implements KeyListener
{
	private FireMenu menu;
	
	public FireMenuInput(FireMenu m)
	{
		this.menu = m;
	}

	@Override
	public void keyPressed(KeyEvent e) 
	{
		if(e.getKeyCode() == KeyEvent.VK_ENTER)
		{
			if(menu.torpedoBay.canFire)
			{
				if(menu.main.resources.getMetal() >= 25)
				{
					double xVel = Math.cos(Math.atan2(menu.main.cursor.getY()-menu.ttY, menu.main.cursor.getX()-menu.ttX))*5;//-(menu.ttX-menu.main.cursor.getX())*5;
					double yVel = Math.sin(Math.atan2(menu.main.cursor.getY()-menu.ttY, menu.main.cursor.getX()-menu.ttX))*5;//-(menu.ttY-menu.main.cursor.getY())*5;
					menu.main.projectileManager.projectileList.add(new Torpedo(menu.ttX*10, menu.ttY*10, xVel, yVel, menu.main, true));
					menu.main.resources.setMetal(menu.main.resources.getMetal()-25);
					menu.torpedoBay.canFire = false;
					menu.torpedoBay.cooldown = 100;
				}
				else
				{
					menu.main.announcementManager.AddAnnouncement(new Announcement("You need 25 metal to fire a torpedo!", Color.red));
				}
			}
		}
	}

	@Override
	public void keyReleased(KeyEvent e) 
	{
		
	}

	@Override
	public void keyTyped(KeyEvent e) 
	{
		
	}
	
}
